#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

set -e

GITTAG=#TAG#
PYTHONVER=#PYTHONVER#

BOOST_VERSION=1.67

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install openssl git boost@$BOOST_VERSION pkg-config jsoncpp cmake protobuf260

brew link --force boost@$BOOST_VERSION

if [ "$PYTHONVER" = "PYTHON2" ]
then
	brew install python@2 boost-python@$BOOST_VERSION

	brew link --force boost-python@$BOOST_VERSION
fi

if [ "$PYTHONVER" = "PYTHON3" ]
then
	brew install python boost-python3
	brew link --force boost-python3
fi

brew link --force protobuf260

rm -rf pulsar
git clone --depth 1 --branch $GITTAG https://github.com/apache/pulsar.git
cd pulsar/pulsar-client-cpp
cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
make _pulsar -j8
cd python

if [ "$PYTHONVER" = "PYTHON2" ]
then
  python2 setup.py bdist_wheel
else
  python3 setup.py bdist_wheel
fi
